<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('asset'))
{
	function asset($param, $group = FALSE, $ignore = FALSE)
	{
		// Get the superobject
		$CI =& get_instance();

		// Load the asset config file, if not loaded already
		$CI->load->config('asset_manager', TRUE);

		// If the ignore flag is set for this asset OR the config is switched off, then just return the file
		if ($ignore || ! $CI->config->item('active', 'asset_manager'))
		{
			// Load the helper, if it's not already
			$CI->load->helper('url');

			// Now just return the file made relative to the site with the site_url function
			echo site_url($param);
		}
		else
		{
			// What query library are we using?
			$CI->load->library('asset_manager/am_'.$CI->config->item('query', 'asset_manager').'_query', FALSE,'am_query');

			// Now call it up
			echo $CI->am_query->get_asset_src($param, $group);
		}
	}
}

if ( ! function_exists('get_cdn_bucket'))
{
	function get_cdn_bucket()
	{
		$CI =& get_instance();
		$CI->load->helper('url');
		return $CI->config->item('cdn_bucket', 'asset_manager') ?
			$CI->config->item('cdn_bucket', 'asset_manager') : parse_url(site_url(), PHP_URL_HOST);
	}
}

if ( ! function_exists('cdn_url'))
{
	function get_cdn_url($remote)
	{
		$CI =& get_instance();
		return $CI->config->item('cdn_url', 'asset_manager').get_cdn_bucket().'/'.$remote;
	}
}